package com.zfei.gfb.bean;

import java.io.Serializable;

/**
 * @author fgh
 */
public class Result implements Serializable {

    private Object data;

    private int code = Status.OK.value();

    private String msg = Status.OK.getReasonPhrase();

    public Result() {
    }

    public Result(Object data, int code, String msg) {
        this.data = data;
        this.code = code;
        this.msg = msg;
    }

    public Result(int code, String msg) {
        this(null, code, msg);
    }

    public Result(Object data, Status status) {
        this(data, status.value(), status.getReasonPhrase());
    }

    public Result(Status status) {
        this(status.value(), status.getReasonPhrase());
    }

    public Result(StatusException e) {
        this(e.getStatusCode(), e.getReasonPhrase());
    }

    public Object getData() {
        return data;
    }

    public void setData(Object data) {
        this.data = data;
    }

    public int getCode() {
        return code;
    }

    public void setCode(int code) {
        this.code = code;
    }

    public String getMsg() {
        return msg;
    }

    public void setMsg(String msg) {
        this.msg = msg;
    }

    public static Result of(Object data) {
        return new Result(data, Status.OK);
    }
}
